<template>
  <div class="dashboard-container">
    <div class="filter-container">
      <el-row :gutter="10" style="width:100%">
        <el-col :span="3">
          <el-input
            v-model="listQuery.tid"
            placeholder="订单号"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="listQuery.batch_no"
            placeholder="批次号"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="listQuery.username"
            placeholder="用户昵称"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-select
            v-model="listQuery.uid"
            clearable
            filterable
            placeholder="选择账户"
            @change="reloadList"
          >
            <el-option v-for="(item, index) in memberList" :key="index" :label="item.username" :value="item.id" />
          </el-select>
        </el-col>
        <el-col :span="5">
          <el-date-picker
            v-model="listQuery.created"
            style="width: 100%;"
            type="datetimerange"
            range-separator="~"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="创建开始日期"
            end-placeholder="创建结束日期"
            :default-time="['00:00:00', '23:59:59']"
          />
        </el-col>
        <el-col :span="6">
          <div>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="reloadList"
            >搜索</el-button>
            <el-button
              class="filter-item"
              style="margin-left: 10px;"
              icon="el-icon-download"
              type="primary"
              @click="download"
            >
              导出
            </el-button>
          </div>

        </el-col>
      </el-row>
    </div>
    <div style="padding:0 20px">

      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        height="calc(100vh - 200px)"
        style="width: 100%;"
        size="mini"
        border
        tooltip-effect="dark"
        :header-cell-style="{ background: '#eaf1fd', color: '#333' }"
      >
        <el-table-column
          label="日期"
          width="150px"
          prop="created"
        />
        <el-table-column label="类型" prop="method" width="100">
          <template #default="{ row }">
            <div>
              <span v-if="row.method == 1" style="color:green">余额</span>
              <span v-if="row.method == 2" style="color:blue">授信</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="事件"
          min-width="250px"
          prop="context"
        />
        <el-table-column
          label="用户昵称"
          min-width="150px"
          prop="user.username"
        />
        <el-table-column
          label="订单号"
          min-width="150px"
          prop="tid"
        />
        <el-table-column
          label="批次号"
          width="150px"
          prop="batch_no"
        />
        <el-table-column
          label="交易前金额"
          width="150px"
          prop="amount_before"
        />
        <el-table-column
          label="交易金额"
          width="150px"
          prop="amount"
        />
        <el-table-column
          label="交易后金额"
          width="150px"
          prop="amount_after"
        />

      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
    <!-- <Detial :detial="detial" :status="status" :visible="visible" @update="closeDraw" @reload="reloadList" /> -->
  </div>
</template>

<script>
import { listFinanceLog, exportListFinanceLog } from '@/api/finance/index'
import { listUser } from '@/api/user/index'

import Pagination from '@/components/Pagination' // secondary package based on el-pagination
// import Detial from './components/flightDetial.vue'

export default {
  name: 'Dashboard',
  components: {
    Pagination
    // Detial
  },
  data() {
    return {
      data_arr: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        tid: '',
        batch_no: '',
        created: [],
        username: ''
      },
      visible: false,
      status: 1,
      id: '',
      detial: {},
      message: ''
    }
  },
  computed: {
  },
  created() {
    this.getList()
    this.getMemberList()
  },
  methods: {
    getMemberList() {
      listUser({
        status: 1,
        limit: 9999999
      }).then(res => {
        this.memberList = res.data.data
      })
    },
    closeDraw() {
      this.visible = false
    },
    addNews() {
      this.status = 1
      this.visible = true
    },
    edit(row) {
      this.detial = { ...row }
      this.status = 2
      this.visible = true
    },
    // delet(row) {
    //   this.$confirm('确认删除该航班, 是否继续?', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     delFlight({
    //       id: row.id
    //     }).then(res => {
    //       this.$message({
    //         type: 'success',
    //         message: '删除成功!'
    //       })
    //       this.getList()
    //     })
    //   }).catch(() => {

    //   })
    // },
    reloadList() {
      this.listQuery.page = 1
      this.visible = false
      this.getList()
    },
    getList() {
      this.listLoading = true
      listFinanceLog(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    download() {
      exportListFinanceLog(this.listQuery).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
      })
    }
  }
}
</script>
<style scoped>
.filter-container{
  padding:20px 20px 10px;
}

.upload-demo{
  margin: 20px 0 10px;
}
</style>
